﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Controllers;

namespace Web
{
    public partial class RoleDept : System.Web.UI.Page
    {
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if(IsPostBack)
            {
                int roleId = int.Parse(Request.QueryString["roleId"]);
                string ddlMenu = Request.Form["ddlMenu"];
                ApolloOaDataContext ctx = new ApolloOaDataContext(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);

                string strSql = @"SELECT * FROM Depts where IsValid=1 and Id not in(SELECT DeptId FROM RoleControllerDepts where RoleId={0} and Controller={1});";
                var list = ctx.ExecuteQuery<Depts>(strSql, roleId, ddlMenu);
                rptDeptList.DataSource = list;
                rptDeptList.DataBind();

                strSql = @"SELECT * FROM Depts where IsValid=1 and Id in(SELECT DeptId FROM RoleControllerDepts where RoleId={0} and Controller={1});";
                var list2 = ctx.ExecuteQuery<Depts>(strSql, roleId, ddlMenu);
                rptChoosedDeptList.DataSource = list2;
                rptChoosedDeptList.DataBind();
            }
        }
    }
}